{% extends 'base.html' %}
{% load myinclusion %}
{% load myuserauth %}
{% block css %}
<!-- iCheck -->
<link href="/static/css/green.css" rel="stylesheet">
{% endblock %}
{% block content %}
<div class="right_col" role="main">
    <div class="">
        <div class="clearfix"></div>

        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>{{ page_name }}<small>|&nbsp;<a href="{% url 'project_list' %}">项目列表</a></small></h2>
                        <ul class="nav navbar-right panel_toolbox">
                            <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                            </li>
                            <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="#">Settings 1</a>
                                </li>
                                <li><a href="#">Settings 2</a>
                                </li>
                            </ul>
                            </li>
                            <li><a class="close-link"><i class="fa fa-close"></i></a>
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">

                        <form class="form-horizontal form-border" method="post" action="" enctype="multipart/form-data">
                            {% csrf_token %}
                            {% if perms.deploy.edit_project %}
                            <fieldset>
                            {% else %}
                            <fieldset disabled="disabled">
                            {% endif %}
                            {% for i in form %}
                            <div class="item form-group">
                                <label class="control-label col-md-2 col-sm-2 col-xs-12" style="text-align:left;">{{ i.label_tag }}
                                </label>
                                <div class="col-md-6 col-sm-6 col-xs-12" {% if forloop.counter == 6 %}data-toggle="tooltip" data-placement="right" title="格式：启动项 | 重启项 | 停止项"{% endif %}>
                                    {{ i }}
                                    <div style="padding-top:10px;">
                                    {{ i.errors }}
                                    </div>
                                </div>
                            </div>
                            {% endfor %}
                            <div class="item form-group">
                                <label class="control-label col-md-2 col-sm-2 col-xs-12" style="text-align:left;">排除文件
                                </label>
                                <div class="col-md-6 col-sm-6 col-xs-12" data-toggle="tooltip" data-placement="right" title="不同步的文件或目录，一行一个">
                                    <textarea class="form-control" name="exclude" rows="5" placeholder=".git">{{ content }}</textarea>
                                </div>
                            </div>
                            <div class="ln_solid"></div>
                            <div class="form-group">
                                <div>
                                    {% ifequal action 'add' %}
                                    <button id="send" type="submit" class="btn btn-success">添加</button>
                                    {% endifequal %}
                                    {% ifequal action 'edit' %}
                                    <button id="send" type="submit" class="btn btn-success">更新</button>
                                    {% endifequal %}
                                </div>
                            </div>
                            </fieldset>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block js %}
<script type="text/javascript" src="/static/js/icheck.min.js"></script>
<script type="text/javascript" src="/static/js/csrf.js"></script>
<!-- validator -->
<!--<script type="text/javascript" src="/static/js/validator.min.js"></script>-->
<script type="text/javascript">
    document.getElementById("id_name").focus();
</script>
<script>
    {% ifequal action 'add' %}
        $("#id_src_passwd").attr('required','required');
        $("#id_src_passwd").attr('placeholder','');
    {% endifequal %}

      // initialize the validator function
    validator.message.date = 'not a real date';

    // validate a field on "blur" event, a 'select' on 'change' event & a '.reuired' classed multifield on 'keyup':
    $('form')
    .on('blur', 'input[required], input.optional, select.required', validator.checkField)
    .on('change', 'select.required', validator.checkField)
    .on('keypress', 'input[required][pattern]', validator.keypress);

    $('.multi.required').on('keyup blur', 'input', function() {
        validator.checkField.apply($(this).siblings().last()[0]);
    });

    $('form').submit(function(e) {
        e.preventDefault();
        var submit = true;

        // evaluate the form using generic validaing
        if (!validator.checkAll($(this))) {
          submit = false;
    }

    return false;
    });
</script>
<!-- /validator -->
{% endblock %}
